package com.zq.it.dao.impl.exam;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zq.it.dao.exam.TPaperSectionDAO;
import com.zq.it.dao.impl.BaseDao;
import com.zq.it.pojo.exam.TPaperSection;

public class TPaperSectionDAOImpl extends BaseDao<TPaperSection> implements TPaperSectionDAO {
	private static final Logger log = LoggerFactory
			.getLogger(TPaperSectionDAOImpl.class);
	// property constants
	public static final String SECTION_NAME = "sectionName";
	public static final String REMARK = "remark";
	public static final String PER_SCORE = "perScore";

	@Override
	public void save(TPaperSection transientInstance) {
		log.debug("saving TPaperSection instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void delete(TPaperSection persistentInstance) {
		log.debug("deleting TPaperSection instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	@Override
	public TPaperSection findById(Long id) {
		log.debug("getting TPaperSection instance with id: " + id);
		try {
			TPaperSection instance = (TPaperSection) getHibernateTemplate()
					.get("com.zq.it.pojo.exam.TPaperSection", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@Override
	public List findByExample(TPaperSection instance) {
		log.debug("finding TPaperSection instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TPaperSection instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TPaperSection as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	public List findBySectionName(Object sectionName) {
		return findByProperty(SECTION_NAME, sectionName);
	}

	@Override
	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	@Override
	public List findByPerScore(Object perScore) {
		return findByProperty(PER_SCORE, perScore);
	}

	@Override
	public List findAll() {
		log.debug("finding all TPaperSection instances");
		try {
			String queryString = "from TPaperSection";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	@Override
	public void attachDirty(TPaperSection instance) {
		log.debug("attaching dirty TPaperSection instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	@Override
	public List findByHql(String hql) {
		return getHibernateTemplate().find(hql);
	}

	@Override
	public void deleteByHql(String hql) {
		super.deleteEntity(hql);
	}
}